@echo off
setlocal enabledelayedexpansion

set ROOT=%~dp0..\
set LIB=%ROOT%lib
set JAR_ROOT=%ROOT%junit-platform-console-standalone-1.10.2.jar
set JAR_LIB=%LIB%\junit-platform-console-standalone-1.10.2.jar
set JAR=

if exist "%JAR_ROOT%" set JAR=%JAR_ROOT%
if not defined JAR if exist "%JAR_LIB%" set JAR=%JAR_LIB%
if not defined JAR (
    echo JUnit standalone jar not found in root or lib. Running setup...
    call "%~dp0setup-test.cmd"
    if errorlevel 1 exit /b 1
    if exist "%JAR_ROOT%" set JAR=%JAR_ROOT%
    if not defined JAR if exist "%JAR_LIB%" set JAR=%JAR_LIB%
)

echo Compiling sources...
pushd "%ROOT%"
javac -cp .;"%JAR%" Calculator.java CalculatorTest.java
if errorlevel 1 (
    popd
    exit /b 1
)

echo Running tests...
java -jar "%JAR%" -c CalculatorTest
set CODE=%ERRORLEVEL%
popd
exit /b %CODE%


